home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / windes.zip / WINDES.H < prev    next >
C/C++ Source or Header  |  1993-07-07  |  5KB  |  130 lines

  1. /* COPYRIGHT (C) Controlled Information Environments 1988, 1989, 1990, 1991 */
  2. /* Patent and Trademark 1975 by International Business Machines Corporation. */
  3.  
  4. #ifndef _INC_WINDES
  5.  
  6. /*ff
  7. *******************************************************************************
  8. *
  9. * Name-Purpose: WinDES.h - Data Encryption Standard (DES) DLL prototypes
  10. *
  11. * Description:    This generic ANSI-C module employs the DES algorithm to encode
  12. *        & decode digital data via 64-bit Electronic Code Book (ECB).
  13. *
  14. *        The DES algorithm uses a 64-bit user-provided private key to
  15. *        take a 64-bit data block through 18 data manipulation stages
  16. *        for either encryption or decryption.  The first and last stages
  17. *        are merely simple bit transpositions - one is the inverse of
  18. *        the other (IP & IP'). The middle 16 stages perform identical
  19. *        complex bit manipulations that vary according to the data. Each
  20. *        bit of the result is a function of each and any bit of both
  21. *        the input data and the key; a change in a single key or data
  22. *        bit has equal probability of changing any output bit.
  23. *
  24. *        This version designed/written by Steven Fisher CDP.
  25. *
  26. * External Interface:
  27. *
  28. *    Semaphores:    None.
  29. *
  30. *    Queues:     None.
  31. *
  32. *    Shared Memory:    None.
  33. *
  34. *
  35. * Side Effect:  None.
  36. *
  37. * Notes:    All comment nomenclature aheres to that in FIPS PUB 46. For
  38. *               additional background, refer to these documents:
  39. *            Advanced Micro Devices Am9568 Technical Manual (1985)
  40. *            ANSI X3.92-1981: Data Encryption Algorithm
  41. *            ANSI X9.17-1985: Financial Institution Key Management
  42. *            FIPS PUB 46: Data Encryption Standard (15 Jan 1977)
  43. *            FIPS PUB 81: DES Modes of Operation
  44. *
  45. ******************************************************************************/
  46.  
  47. /* local defines in case WINDOWS.H is unavailable */
  48. #ifndef _INC_WINDOWS
  49. #define FAR            _far
  50. typedef int             BOOL;
  51. typedef unsigned char   BYTE;
  52. #ifndef __BORLANDC__
  53. typedef unsigned int    WORD;
  54. #endif
  55. typedef unsigned long   DWORD;
  56. typedef char NEAR       *PSTR;
  57. typedef char NEAR       *NPSTR;
  58. typedef char FAR        *LPSTR;
  59. typedef BYTE NEAR       *PBYTE;
  60. typedef BYTE FAR        *LPBYTE;
  61. typedef int NEAR        *PINT;
  62. typedef int FAR         *LPINT;
  63. typedef WORD NEAR       *PWORD;
  64. typedef WORD FAR        *LPWORD;
  65. typedef long NEAR       *PLONG;
  66. typedef long FAR        *LPLONG;
  67. typedef DWORD NEAR      *PDWORD;
  68. typedef DWORD FAR       *LPDWORD;
  69. typedef void FAR        *LPVOID;
  70. #endif
  71.  
  72. /*ff
  73.  ******************************************************************************
  74.  *
  75.  * Name: DesEnCrypt, DesDeCrypt
  76.  *
  77.  ******************************************************************************
  78.  *
  79.  * Description:    Performs electronic code-book (ECB) encryption via DES.
  80.  *           The electronic code book is a direct implementation of the
  81.  *           DES algorithm. The analogy to a code book arises because
  82.  *           the same plain text always generates the same ciphered text
  83.  *           for a given cryptographic key. This is a weakness in that
  84.  *           identical blocks of plain text generate identical blocks
  85.  *           of ciphered text. For randomly-accessed data, however,
  86.  *           this data block sequence independence is crucial.
  87.  *
  88.  *           The input block is first permuted to distribute its bits
  89.  *           across a work buffer.  Then sixteen passes are made, where
  90.  *                 a unique derivation of the input key is used to cipher the
  91.  *           the contents of the work buffer, the ciphered result is XORed
  92.  *           with half of the unciphered data, the left and right halves
  93.  *           of the work buffer swapped, and the result fed into the next
  94.  *           iteration. After the 16 passes are completed, the result data
  95.  *           is inversely permuted to undo the bit relocations caused in
  96.  *           the first step. Note that the positions are restored, but not
  97.  *           the value of the individual bits; data bit 1 is moved to bit
  98.  *           58, ciphered 16 times, and its new value moved back to bit 1.
  99.  *
  100.  *           ECB gives an error extension characteristic which protects
  101.  *           against fraudulent data insertion, deletion, or alteration
  102.  *           in a block. A one-bit error in either the input text block
  103.  *           or the key causes an average error rate of 50% for its
  104.  *                 output block. An error in one text block will not affect
  105.  *                 any other block; there is no error extension between blocks.
  106.  *
  107.  *           The input and output block size is 64 bits. Since data blocks
  108.  *           are independently ciphered, this mode is qualified for disk
  109.  *           applications employing random access.
  110.  *
  111.  * Synopsis:       DesXxCrypt(key,inp,out,cnt)
  112.  *
  113.  *    Input:       key - 64-bit DES key
  114.  *                 inp - pointer to buffer of input data
  115.  *                 out - pointer to buffer for result data
  116.  *                 cnt - count of 64-bit blocks to be processed
  117.  *
  118.  *    Output:    None.
  119.  *
  120.  * Side Effect:       Writes data to output buffer "out".
  121.  *
  122.  *****************************************************************************/
  123. extern  VOID FAR PASCAL DesEnCrypt(LPBYTE key,LPBYTE inp,LPBYTE out,WORD cnt);
  124. extern  VOID FAR PASCAL DesDeCrypt(LPBYTE key,LPBYTE inp,LPBYTE out,WORD cnt);
  125.  
  126. #define _INC_WINDES
  127. #endif
  128.  
  129. /* end of header */
  130.